package com.tobeface.wechat.message.builder;

import com.google.common.collect.Maps;
import com.tobeface.modules.lang.Requires;
import com.tobeface.wechat.message.WeChatMessageBuilder;
import com.tobeface.wechat.message.WeChatMessagePayloads;
import com.tobeface.wechat.message.WeChatMessageTypes;

import java.util.Map;

/**
 * @author loudyn
 */
public class MusicTypedMessageBuilder extends AbstractTypedMessageBuilder {

    private String title;
    private String descr;
    private String musicUrl;
    private String hqMusicUrl;
    private String thumbMediaId;

    /**
     * @param parent
     */
    public MusicTypedMessageBuilder(WeChatMessageBuilder parent) {
        super(parent);
    }

    public MusicTypedMessageBuilder title(String title) {
        Requires.hasText(title, "title must not be null or empty!");
        this.title = title;
        return this;
    }

    public MusicTypedMessageBuilder descr(String descr) {
        Requires.hasText(descr, "descr must not be null or empty!");
        this.descr = descr;
        return this;
    }

    public MusicTypedMessageBuilder musicUrl(String musicUrl) {
        Requires.hasText(musicUrl, "musicUrl must not be null or empty!");
        this.musicUrl = musicUrl;
        return this;
    }

    public MusicTypedMessageBuilder hqMusicUrl(String hqMusicUrl) {
        Requires.hasText(hqMusicUrl, "hqMusicUrl must not be null or empty!");
        this.hqMusicUrl = hqMusicUrl;
        return this;
    }

    public MusicTypedMessageBuilder thumbMediaId(String thumbMediaId) {
        Requires.hasText(thumbMediaId, "thumbMediaId must not be null or empty!");
        this.thumbMediaId = thumbMediaId;
        return this;
    }

    @Override
    protected void configPayloads(Map<String, Object> payloads) {
        Map<String, String> payload = Maps.newHashMap();
        payload.put(WeChatMessagePayloads.TITLE_PAYLOAD, title);
        payload.put(WeChatMessagePayloads.DESCR_PAYLOAD, descr);
        payload.put(WeChatMessagePayloads.THUMB_MEDIAID_PAYLOAD, thumbMediaId);
        payload.put(WeChatMessagePayloads.MUSIC_URL_PAYLOAD, musicUrl);
        payload.put(WeChatMessagePayloads.HQ_MUSIC_URL_PAYLOAD, hqMusicUrl);
        payloads.put("Music", payload);
        payloads.put(WeChatMessagePayloads.MSGTYPE_PAYLOAD, WeChatMessageTypes.MUSIC);
    }
}
